import { RouteRecordRaw } from "vue-router";

export const modulesRoutes: Array<RouteRecordRaw> = [];
const modulesFiles = import.meta.globEager("/src/modules/**/router/*.ts");
const getModuleName = (path: string) => {
  return path.split('/')[3]
};
Object.keys(modulesFiles).forEach((path) => {
  const routes = modulesFiles[path].default;
  const tree = (node) => {
    if (node.children) {
      node.children.forEach(child => tree(child));
    }
    node.meta.moduleName = getModuleName(path);
  };
  routes.forEach(route => {
    tree(route);
    modulesRoutes.push(route);
  });
});

